﻿// -------------------------------------------------------------------------
//    @FileName         :    NFSkyArenaPart.cpp
//    @Author           :    gaoyi
//    @Date             :    24-8-30
//    @Email            :    445267987@qq.com
//    @Module           :    NFSkyArenaPart
//
// -------------------------------------------------------------------------

#include "NFSkyArenaPart.h"

#include "proto_cs_common.pb.h"
#include "proto_db.pb.h"

NFSkyArenaPart::NFSkyArenaPart()
{
    if (EN_OBJ_MODE_INIT == NFShmMgr::Instance()->GetCreateMode())
    {
        CreateInit();
    }
    else
    {
        ResumeInit();
    }
}

NFSkyArenaPart::~NFSkyArenaPart()
{
}

int NFSkyArenaPart::CreateInit()
{
    m_stData.today_box_picked.resize(m_stData.today_box_picked.max_size());
    return 0;
}

int NFSkyArenaPart::ResumeInit()
{
    return 0;
}

int NFSkyArenaPart::LoadFromDB(const proto_ff::tbRoleDetail* pDBData)
{
    m_stData.FromPb(pDBData->role_play_data().skyarena_data());
    return 0;
}

int NFSkyArenaPart::InitConfig(proto_ff::tbRoleDetail* pDbData, const RoleOne& stRoleOne)
{
    CHECK_NULL(0, pDbData);
    auto pRoleSkyarenaData = pDbData->mutable_role_play_data()->mutable_skyarena_data();
    CHECK_NULL(0, pRoleSkyarenaData);

    pRoleSkyarenaData->set_mmr(1000);
    pRoleSkyarenaData->mutable_statistics_today()->set_floor_max(1);
    pRoleSkyarenaData->mutable_statistics_season()->set_floor_max(1);
    pRoleSkyarenaData->mutable_statistics_history()->set_floor_max(1);
    pRoleSkyarenaData->set_last_daily_divison_reward_got_time(NF_ADJUST_TIMENOW());

    pRoleSkyarenaData->set_season_id(1);
    for (size_t i = 0; i < m_stData.today_box_picked.size(); ++i)
    {
        pRoleSkyarenaData->add_today_box_picked(0);
    }

    pRoleSkyarenaData->set_sa_ban_score(20);
    pRoleSkyarenaData->set_sa_ban_mode(1);
    return 0;
}

int NFSkyArenaPart::SaveDB(proto_ff::tbRoleDetail* pDBData)
{
    m_stData.ToPb(pDBData->mutable_role_play_data()->mutable_skyarena_data());
    return 0;
}

int NFSkyArenaPart::MakePlayerDataCS(proto_ff::Proto_CSGetRoleRsp* pCSGetRoleRsp)
{
    return 0;
}

int NFSkyArenaPart::MakeCityPlayerData(proto_ff::CityRoleInfo* pGCCityRoleInfo)
{
    return 0;
}

int NFSkyArenaPart::MakeDataCS(proto_ff::Proto_CSSkyArenaData* pRoleSkyarenaData) const
{
    pRoleSkyarenaData->set_season_id(m_stData.season_id);
    pRoleSkyarenaData->set_season_start_time(0);
    pRoleSkyarenaData->set_season_finish_time(0);

    pRoleSkyarenaData->set_current_floor(m_stData.statistics_today.floor_max);
    m_stData.statistics_today.ToPb(pRoleSkyarenaData->mutable_statistics_today());
    m_stData.statistics_season.ToPb(pRoleSkyarenaData->mutable_statistics_season());
    m_stData.statistics_history.ToPb(pRoleSkyarenaData->mutable_statistics_history());

    pRoleSkyarenaData->set_battle_score(m_stData.show_score);
    for (int i = 0; i < m_stData.today_box_picked.size(); ++i)
    {
        pRoleSkyarenaData->add_today_acquired_box(m_stData.today_box_picked[i]);
    }

    pRoleSkyarenaData->set_match_cd(0);
    pRoleSkyarenaData->set_sa_ban_mode(std::max(1, m_stData.sa_ban_mode));
    pRoleSkyarenaData->set_sa_ban_time(m_stData.sa_ban_time);
    pRoleSkyarenaData->set_sa_ban_score(m_stData.sa_ban_score);
    return 0;
}
